package com.eboss2.sbs.activity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.eboss2.sbs.R;
import com.eboss2.sbs.activity.base.BaseActivity;
import com.mytools.tool.activityManager.MyActivityManager;
import com.tool.utils.utils.CreateCodeUtil;
import com.tool.utils.utils.ScreenUtils;
import com.tool.utils.utils.StringUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ReceiptBarcodeActivity extends BaseActivity implements View.OnClickListener {

    @BindView(R.id.tv_record)
    TextView tvRecord;
    private String barcode;
    private String shopName;
    private TextView tvShopName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = this;
        setContentView(R.layout.activity_receipt_barcode);
        ButterKnife.bind(this);
        MyActivityManager.getInstance().addActivity(this);
        barcode = getIntent().getStringExtra("barcode");
        shopName = getIntent().getStringExtra("shopName");
        initView();
    }

    private void initView() {
        setTvText(R.id.tv_title, "收款二维码");
        findViewById(R.id.titleback_btn_back).setOnClickListener(this);

        tvShopName = textView(R.id.shopName);
        tvShopName.setText(StringUtils.isBlank(shopName) ? "" : shopName);

        Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.sm_logo);
        ImageView img_barcode = (ImageView) findViewById(R.id.img_barcode);
        img_barcode.setImageBitmap(CreateCodeUtil.createQRImage(barcode, ScreenUtils.dp2px(168, mContext),
                ScreenUtils.dp2px(168, mContext), bmp, false));
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.titleback_btn_back:
                finish();
                break;

            default:
                break;
        }
    }

    @OnClick(R.id.tv_record)
    public void onViewClicked() {
        startActivity(new Intent(mContext, ShopRecordActivity.class));
    }
}
